<?php
session_start();
include "../../config/koneksi.php";
include "../../config/library.php";

$module=$_GET[module];
$act=$_GET[act];

// Hapus poling
if ($module=='konsultasi' AND $act=='hapus'){
  mysql_query("DELETE FROM konsultasi WHERE id_konsultasi='$_GET[id]'");
  header('location:../../media.php?module='.$module);
}

// Input poling
elseif ($module=='konsultasi' AND $act=='balas'){
  mysql_query("INSERT INTO detail_konsultasi(id_konsultasi, tgl_detail, hasil_konsultasi, 
                                  username) 
	                       VALUES('$_POST[id]', '$tgl_sekarang', '$_POST[hasil_konsultasi]',
                                '$_SESSION[namauser]')");
	mysql_query("UPDATE konsultasi SET status_konsultasi = 'SUDAH DIJAWAB'
                          WHERE id_konsultasi = '$_POST[id]'");
  
	$id_member = $_POST[id_member];
	$regid = $_POST[gcm_regid];
	/* $message = "Konsultasi Anda sudah dibalas ya :-)"; */
	$message = $_POST[hasil_konsultasi];
	/*
	echo "<hr>id_member : " . $id_member;
	echo "<hr>regid : " . $regid;
	echo "<hr>message : " . $message;
	*/
	header('location:../../gcm_server/send_message2.php?regId='.$regid.'&message='.$message);
	
	/* header('location:../../media.php?module='.$module); */
  
}

// Update poling
elseif ($module=='konsultasi' AND $act=='update'){
  mysql_query("UPDATE detail_konsultasi SET tgl_detail = '$tgl_sekarang',
                                 hasil_konsultasi   = '$_POST[hasil_konsultasi]'  
                          WHERE id_detail = '$_POST[id]'");

	$id_member = $_POST[id_member];
	$regid = $_POST[gcm_regid];
	/* $message = "Konsultasi Anda sudah dibalas ya :-)"; */
	$message = $_POST[hasil_konsultasi];
	
	header('location:../../gcm_server/send_message2.php?regId='.$regid.'&message='.$message);
    /* header('location:../../media.php?module='.$module); */
}
?>
